package dbhandler;

import evthandler.EventMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class Relative {

    private Guest guest;
    private Guest relative;

    /**
     *
     */
    public Relative() {
    }

    /**
     *
     * @param id
     */
    public Relative(Guest guest, Guest relative) {
        this.guest = guest;
        this.relative = relative;
    }

    /**
     * Returns the relative to the guest
     * @param g
     * @return ArrayList of Relatives
     */
    public ArrayList<Relative> getRelatives(Guest g) {
        ArrayList<Relative> relatives = new ArrayList<Relative>();
        ArrayList<Integer> temp = new ArrayList<Integer>();
        try {
            ResultSet rs = DbCon.getInstance().executeQuery("SELECT relativeNo FROM relative WHERE guestNo=" + g.getGuestNo());
            while (rs.next()) {
                temp.add(rs.getInt("relativeNo"));
            }
        } catch (SQLException ex) {
            new EventMessage("SQL error in Relative.getRelatives()", "There was an error performing the sql inquery\n").showException(ex);
        }
        for (int i = 0; i < temp.size(); i++) {
            Guest r = new Guest(temp.get(i));
            relatives.add(new Relative(g,r));
        }
        return relatives;
    }

    /**
     *
     * @return
     */
    public Guest getRelative() {
        return relative;
    }
}
